package com.opensource.svgaplayer;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Environment;
import android.util.Log;
import android.util.TypedValue;

import com.opensource.svgaplayer.utils.log.LogUtils;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Utils {
    //判断vpn


    //保存图片
    public static String SaveImage(Bitmap bitmap, String path, String name) {
        if (bitmap == null) {
            return null;
        }

//        if (!FileUtil.isExistFile(FileUtil.getExternalStorageDir().concat(path))) {
//            FileUtil.makeDir(FileUtil.getExternalStorageDir().concat(path));
//        }
//        File appDir = new File(FileUtil.getExternalStorageDir().concat(path));
        Log.d("xxxxxxxxxxxxxx", "11111111111111" +" ");
        String newPath = LeanApp.getInstance().getPath() + "/" + path;
        Log.d("xxxxxxxxxxxxxx", "22222222" +" " + newPath);
        File files = new File(newPath);
        Log.d("xxxxxxxxxxxxxx", "3333333" +" " + files);
        if(!files.exists()){
            FileUtil.makeDir(newPath);
        }
        Log.d("xxxxxxxxxxxxxx", "444444" + files);
       File file = new File(newPath, name);
//        File file = new File(LeanApp.app.getPackageName(), name);
        Log.d("xxxxxxxxxxxxxx", "5555555" + file);
        java.io.FileOutputStream fos = null;
        try {
            fos = new java.io.FileOutputStream(file);
            bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
            fos.flush();
            return file.getAbsolutePath();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (fos != null) {
                try {
                    fos.close();
                } catch (java.io.IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return null;
    }





}
